import Request from '../http/Request'
import {
  // 滑块图片请求地址
  SWIPER,
  // 热门分类
  HOTCATE,
  // 精品好菜
  GOOKCOOK
} from '../config/uri'

// 数据模型，获取数据和数据处理
class IndexModel extends Request {

  /**
   * 返回Promise
   */
  getSwiper() {
    return this.get(SWIPER)
  }

  /**
   * 返回Promise
   */
  async getHotCateData() {
    let ret = await this.get(HOTCATE)
    let data = ret.data
    data = data.map(item => ({
      icon: item.img,
      text: item.title
    }))
    return Promise.resolve(data)
  }

  /**
   * 获取精品好菜数据
   * @param int page 页码数 默认1
   * @return Promise对象
   */
  async getGookCookData(page = 1) {
    // return this.get(GOOKCOOK + page)
    let ret = await this.get(GOOKCOOK)
    // 只取10条数据
    let data = ret.data.data.slice(0, 10)
    return Promise.resolve(data)
  }


  // 搜索数据
  async getSearchData(kw = '') {
    let ret = await this.get(GOOKCOOK)
    // 只取10条数据
    let data = ret.data.data.slice(10, 20)
    return Promise.resolve(data)
  }





}

export default new IndexModel